package com.yunxi.poc.starbucks.controller;

import com.yunxi.poc.starbucks.entity.ReportEntity;
import com.yunxi.poc.starbucks.service.IReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author Mingzhi
 */
@RestController
@RequestMapping(value = "/starbucks/report")
public class ReportController {

    private IReportService reportService;

    /**
     * 每日订单
     *
     * @param year
     * @param month
     * @param day
     * @return
     */
    @GetMapping(value = "line")
    public ResponseEntity<List<ReportEntity>> lineData(
            @RequestParam(value = "storeId") String storeId,
            @RequestParam(value = "year") Integer year,
            @RequestParam(value = "month") Integer month,
            @RequestParam(value = "day") Integer day) {
        System.out.printf("year: %s, month: %s, day: %s, storeId: %s%n", year, month, day, storeId);
        LocalDateTime startTime = LocalDateTime.of(year, month, day, 0, 0);
        LocalDateTime endTime = startTime.plusDays(1L);

        ReportEntity query = new ReportEntity();
        query.setStoreId(storeId);
        query.setQueryStartTime(startTime);
        query.setQueryEndTime(endTime);

        return ResponseEntity.ok(reportService.list(query));
    }

    @Autowired
    public void setReportService(IReportService reportService) {
        this.reportService = reportService;
    }
}
